package io

import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
)

func Testpath() {
	a, _ := filepath.Abs("a.txt")
	fmt.Println(a)

	path := "/Users/fanshuai/3/"
	fmt.Println(filepath.Base(path))
	fmt.Println(filepath.Dir(path))

	/*files, _ := filepath.Glob("/Users/fanshuai/*")
	fmt.Println(files)*/

	filepath.Walk("/Users/fanshuai/media/pic", func(path string, info os.FileInfo, err error) error {
		fmt.Println(path)
		return nil
	})
}

func TestDir() {
	err := os.MkdirAll("/Users/fanshuai/test", 0777)
	fmt.Println(err)

	err = os.MkdirAll("/Users/fanshuai/test/1/2/3", 0777)
	fmt.Println(err)

	stat, err2 := os.Stat("/Users/fanshuai")
	stat.IsDir()

	if err2 == nil {
		fmt.Println("file exists")
	} else if os.IsNotExist(err2) {
		fmt.Println("file not exists")
	}

	files, _ := ioutil.ReadDir("/Users/fanshuai/Docker")
	for _, fileinfo := range files {
		fmt.Println(fileinfo.Name(), fileinfo.IsDir())
	}
}
